package org.dream.domain;

import java.util.ArrayList;
import java.util.List;

import org.dream.util.DoubleUtil;


/**
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class Account {
	private double yuer;//账户余额
	private String stockCode;//股票编码
	private int stockNum;//股票数量
	private boolean wantMaiRu;//是否可以买入
	
	private List<ImitationDeal> jiaoYis = new ArrayList<ImitationDeal>();

	public List<ImitationDeal> getJiaoYis() {
		return jiaoYis;
	}

	public void setJiaoYis(List<ImitationDeal> jiaoYis) {
		this.jiaoYis = jiaoYis;
	}

	public boolean isWantMaiRu() {
		return wantMaiRu;
	}

	public void setCanMaiRu(boolean maiRu) {
		this.wantMaiRu = maiRu;
	}

	public double getYuer() {
		return yuer;
	}

	public void setYuer(double money) {
		this.yuer = money;
	}

	public String getStockCode() {
		return stockCode;
	}

	public void setStockCode(String stockCode) {
		this.stockCode = stockCode;
	}

	public int getStockNum() {
		return stockNum;
	}

	public void setStockNum(int stockNum) {
		this.stockNum = stockNum;
	}

	/**
	 * 买入
	 * 
	 * @return
	 */
	public void maiRu(Daydeal daydeal,double cause) {
		
		// 交易记录
		ImitationDeal jiaoYi = new ImitationDeal();
		jiaoYi.setDaydeal(daydeal);
		int num=(int) (this.yuer / daydeal.getOPEN());
		num=(num/100)*100;
		jiaoYi.setNum(num);
		jiaoYi.setPrice(daydeal.getOPEN());
		jiaoYi.setKind("1");
		jiaoYi.setStockCode(daydeal.getCode());
		jiaoYi.setCause(cause);
		jiaoYi.setDate(daydeal.getDAY());
		this.getJiaoYis().add(jiaoYi);
		
		// 所需要花费
		jiaoYi.setMoney(DoubleUtil.changeDecimal(daydeal.getOPEN() * jiaoYi.getNum(), 2));
		
		this.setYuer(this.getYuer() - jiaoYi.getMoney());
		this.setYuer(DoubleUtil.changeDecimal(this.getYuer(), 2));
		this.setStockCode(daydeal.getCode());
		this.setStockNum(jiaoYi.getNum());
		this.setCanMaiRu(false);
		jiaoYi.setYuer(this.getYuer());
		//设置股票持股
		jiaoYi.haveNum=jiaoYi.getNum();
	}

	/**
	 * 卖出
	 * 
	 * @param price
	 * @param stockCodeText
	 */
	public void maiChu(Daydeal daydeal,double cause) {
		// 交易记录
		ImitationDeal jiaoYi = new ImitationDeal();
		jiaoYi.setDaydeal(daydeal);
		jiaoYi.setNum(this.getStockNum());
		jiaoYi.setPrice(daydeal.getOPEN());
		jiaoYi.setKind("0");
		jiaoYi.setStockCode(daydeal.getCode());
		jiaoYi.setCause(cause);
		jiaoYi.setDate(daydeal.getDAY());
		this.getJiaoYis().add(jiaoYi);
		// 所需要花费
		jiaoYi.setMoney(DoubleUtil.changeDecimal(daydeal.getOPEN() * jiaoYi.getNum(), 2));
		this.setYuer(this.getYuer() +jiaoYi.getMoney());
		this.setYuer(DoubleUtil.changeDecimal(this.getYuer(), 2));
		this.setStockCode(daydeal.getCode());
		this.setStockNum(0);
		this.setCanMaiRu(true);
		jiaoYi.setYuer(this.getYuer());
		//设置股票持股数
		jiaoYi.haveNum=0;


	}

}
